package cn.wolfcode.shop.seckillserver.mapper;

import cn.wolfcode.shop.seckillapi.domain.OrderInfo;
import cn.wolfcode.shop.seckillapi.domain.SeckillOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface SeckillOrderMapper {

    @Select("select * from t_seckill_order where good_id = #{goodId} and user_id = #{userId}")
    SeckillOrder findByGoodIdAndUserId(@Param("goodId") Long goodId, @Param("userId") Long userId);

    @Insert("insert into t_seckill_order(user_id,good_id,order_no) values (#{userId},#{goodId},#{orderNo})")
    int createSeckillOrder(SeckillOrder seckillOrder);

    @Select("select * from t_order_info where order_no = #{orderNo}")
    OrderInfo findByOrderNo(String orderNo);

    @Update("update t_order_info set status = #{status} where order_no = #{orderNo} and status = 0")
    int updateStatus(@Param("orderNo") String orderNo, @Param("status")Integer status);

    @Update("update t_order_info set status = #{status},pay_date = now() where order_no = #{orderNo} and status = 0")
    int updatePayState(@Param("orderNo") String orderNo,@Param("status") Integer status);


    @Select("select * from t_seckill_order")
    List<SeckillOrder> list();
}
